Initialize your Service
In this guide, you will create a service called dummy-controller
in C, interface it with the official imaging
and actuator
services, upload it to the Rover and execute it.

Elias Groot
Software Lead, Project Administrator
Before you can get started writing any code, make sure to properly initialize your workspace on your own device (your laptop).
- Create a folder called dummy-controller and enter it
mkdir dummy-controller && cd dummy-controller
- Initialize the required folder structure using
roverctl
and enter the required information
roverctl service init
(Alternatively, you can clone our C service template)
- Upload the initial version of your service to the Rover (if it is powered on)
roverctl service sync
- (Optional) open the directory in VS Code and hit ctrl+shift+p. Then select "Dev Containers: Rebuild and Reopen in Container". The build process might take a while the first time. Once built, open a terminal in VS Code and try to build the service
make build
Service Entrypoint
Take a look at the main()
function in src/main.c. You will see a reference to run()
. The defined user_program()
function is the entrypoint of your service, it will be executed once the roverlib
processed your service data. This is where your code should live.
The provided user_program()
function already illustrates how to use the most important methods that the roverlib-c
shared object provides. Try and see if you can follow what the example code does and why you might need this.
After that, clear the contents of the user_program()
function. We will start from scratch, so your source code should look like this:
#include <roverlib.h>
#include <sys/time.h>
#include <unistd.h>
long long current_time_millis() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (long long)(tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
}
// The main user space program
// this program has all you need from roverlib: service identity, reading, writing and configuration
int user_program(Service service, Service_configuration *configuration) {
}
// This is just a wrapper to run the user program
// it is not recommended to put any other logic here
int main() {
return run(user_program);
}